<template>
  <span>{{ nowDate }}</span>
</template>

<script>
export default {
  name: "itemView",

  data() {
    return {
      nowDate: "",
    };
  },
  created() {
    this.updateTime();
  },
  methods: {
    //时间走动
    updateTime() {
      const today = new Date();
      let y = today.getFullYear();
      let mt = today.getMonth() + 1; // 月份是从0开始的
      let d = today.getDate();
      let h = today.getHours();
      let m = today.getMinutes();
      let s = today.getSeconds();
      mt = mt < 10 ? "0" + mt : mt;
      d = d < 10 ? "0" + d : d;
      h = h < 10 ? "0" + h : h;
      m = m < 10 ? "0" + m : m;
      s = s < 10 ? "0" + s : s;
      const timeString = y + "-" + mt + "-" + d + " " + h + ":" + m + ":" + s;
      // 显示时间到页面上的元素
      this.nowDate = timeString;
      // 每秒更新时间
      setTimeout(this.updateTime, 1000);
    },
  },
};
</script>

<style lang="scss" scoped>
span {
  font-size: 18px;
  color: #8993f2;
  margin: 0 35px 0 30px;
}
</style>
